package com.lagou.cl.service.impl;

import com.lagou.cl.dao.PayOrderDao;
import com.lagou.cl.pojo.PayOrder;
import com.lagou.cl.service.PayOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

/**
 * @author 程  林
 * @date 2020-10-12 00:59
 * @description //
 * @since V1.0.0
 */
@Service
public class PayOrderServiceImpl implements PayOrderService {

	@Autowired
	private PayOrderDao payOrderDao;

	@Override
	public void addOrder(PayOrder payOrder) {

		payOrderDao.save(payOrder);
	}

	@Override
	public PayOrder queryPayOrderByOrderId(String orderId) {
		PayOrder payOrder = new PayOrder();
		payOrder.setOrderId(orderId);

		Example<PayOrder> example = Example.of(payOrder);
		Optional<PayOrder> one = payOrderDao.findOne(example);
		return one.orElse(null);
	}

	@Override
	public void updateOrder(PayOrder payOrder) {
		payOrderDao.save(payOrder);
	}

	@Override
	public List<PayOrder> queryPayOrders(Integer state) {

		PayOrder payOrder = new PayOrder();
		payOrder.setState(state);

		Example<PayOrder> example = Example.of(payOrder);

		return payOrderDao.findAll(example);
	}
}
